﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Wise.Util
{
    /// <summary>
    /// 助手基类
    /// 自定义已存在助手的方法：
    /// 1.通过继承助手类并Override其中的成员，即可重写成员
    /// 2.再通过ChangeInstance静态方法即可将默认实现替换成自定义实现
    /// </summary>
    public abstract class HelperBase<THelper>
        : HelperBase
        where THelper : HelperBase, new()
    {
        static HelperBase()
        {
            instance = new THelper();
        }

        /// <summary>
        /// 将类型实现更换为自定义实现
        /// </summary>
        public static void ChangeInstance(THelper newInstance)
        {
            if (newInstance == null)
                throw new ArgumentNullException();
            instance = newInstance;
        }

        /// <summary>
        /// 实现对象
        /// </summary>
        protected static THelper instance = null;


    }

    /// <summary>
    /// 助手基类
    /// </summary>
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
    public class HelperBase 
    {


        /// <summary>
        /// 可以复用
        /// </summary>
        public virtual bool IsReusable
        {
            get
            {
                return true;
            }
        }

        /// <summary>
        /// 安装之前
        /// </summary>
        /// <returns></returns>
        public virtual bool OnBeforeInstall(string instanceTypeName, string interfaceTypeName, ref Type instanceType, ref Type interfaceType)
        {
            return true;
        }

        /// <summary>
        /// 安装时
        /// </summary>
        public virtual void AfterInstalled(Type instanceType, Type interfaceType)
        {

        }
    }
}
